package com.hsxxherp.ation.business.user.center.error;

import com.hsxxherp.ation.common.error.AtionError;

/**
 * 用户中心组建异常处理
 */
public class AtionUserCenterErrorException extends Exception {
    /**
     * 默认是500，这里沿用HTTP状态码
     */
    private static final String DEFAULT_ERROR_CODE = "500";

    private final AtionError error;

    public AtionUserCenterErrorException() {
        this.error = AtionError.builder().build();
    }

    /**
     * 注入错误
     *
     * @param error
     */
    public AtionUserCenterErrorException(AtionError error) {
        super(error.toString());
        this.error = error;
    }

    /**
     * 将自定义报错和异常
     *
     * @param error
     * @param cause
     */
    public AtionUserCenterErrorException(AtionError error, Throwable cause) {
        super(error.toString(), cause);
        this.error = error;
    }

    /**
     * 处理系统异常
     *
     * @param cause
     */
    public AtionUserCenterErrorException(Throwable cause) {
        super(cause.getMessage(), cause);
        this.error = AtionError.builder().errorCode(DEFAULT_ERROR_CODE).errorMessage(cause.getMessage()).build();
    }

    // 处理外部已知异常
    public AtionUserCenterErrorException(String message
            , Throwable cause) {
        super(message, cause);
        this.error = AtionError.builder().errorMessage(message).errorCode(DEFAULT_ERROR_CODE).build();
    }

    public AtionError getError() {
        return error;
    }
}
